package com.esri.core.geometry;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public class SegmentIteratorImpl {
    protected boolean m_bCirculator;
    protected boolean m_bNeedsUpdate;
    protected int m_currentPathIndex;
    protected Segment m_currentSegment;
    protected int m_currentSegmentIndex;
    protected Point2D m_dummyPoint;
    protected Line m_line;
    protected int m_nextPathIndex;
    protected int m_nextSegmentIndex;
    protected MultiPathImpl m_parent;
    protected int m_prevPathIndex;
    protected int m_prevSegmentIndex;
    protected int m_segmentCount;

    public Segment nextCurve() {
        return null;
    }

    public SegmentIteratorImpl(MultiPathImpl multiPathImpl) {
        this.m_currentSegmentIndex = -1;
        this.m_nextSegmentIndex = 0;
        this.m_nextPathIndex = 0;
        this.m_currentPathIndex = -1;
        this.m_parent = multiPathImpl;
        this.m_segmentCount = _getSegmentCount(0);
        this.m_bCirculator = false;
        this.m_currentSegment = null;
        this.m_dummyPoint = new Point2D();
    }

    public SegmentIteratorImpl(MultiPathImpl multiPathImpl, int i) {
        if (i < 0 || i >= multiPathImpl.getPointCount()) {
            throw new IndexOutOfBoundsException();
        }
        this.m_currentSegmentIndex = -1;
        int pathIndexFromPointIndex = multiPathImpl.getPathIndexFromPointIndex(i);
        this.m_nextSegmentIndex = i - multiPathImpl.getPathStart(pathIndexFromPointIndex);
        this.m_nextPathIndex = pathIndexFromPointIndex + 1;
        this.m_currentPathIndex = pathIndexFromPointIndex;
        this.m_parent = multiPathImpl;
        this.m_segmentCount = _getSegmentCount(pathIndexFromPointIndex);
        this.m_bCirculator = false;
        this.m_currentSegment = null;
        this.m_dummyPoint = new Point2D();
    }

    public SegmentIteratorImpl(MultiPathImpl multiPathImpl, int i, int i2) {
        if (i < 0 || i >= multiPathImpl.getPathCount() || i2 < 0) {
            throw new IndexOutOfBoundsException();
        }
        if (i2 >= multiPathImpl.getPathSize(i) - (!multiPathImpl.isClosedPath(i))) {
            throw new IndexOutOfBoundsException();
        }
        this.m_currentSegmentIndex = -1;
        this.m_nextSegmentIndex = i2;
        this.m_currentPathIndex = i;
        int i3 = i2 + 1;
        this.m_nextPathIndex = i3;
        this.m_parent = multiPathImpl;
        this.m_segmentCount = _getSegmentCount(i3);
        this.m_bCirculator = false;
        this.m_currentSegment = null;
        this.m_dummyPoint = new Point2D();
    }

    void a(SegmentIteratorImpl segmentIteratorImpl) {
        if (this.m_parent != segmentIteratorImpl.m_parent) {
            throw new GeometryException("invalid_call");
        }
        this.m_currentSegmentIndex = segmentIteratorImpl.m_currentSegmentIndex;
        this.m_nextSegmentIndex = segmentIteratorImpl.m_nextSegmentIndex;
        this.m_currentPathIndex = segmentIteratorImpl.m_currentPathIndex;
        this.m_nextPathIndex = segmentIteratorImpl.m_nextPathIndex;
        this.m_segmentCount = segmentIteratorImpl.m_segmentCount;
        this.m_bCirculator = segmentIteratorImpl.m_bCirculator;
        this.m_currentSegment = null;
    }

    public Segment nextSegment() {
        if (this.m_currentSegmentIndex != this.m_nextSegmentIndex) {
            _updateSegment();
        }
        if (this.m_bCirculator) {
            this.m_nextSegmentIndex = (this.m_nextSegmentIndex + 1) % this.m_segmentCount;
        } else {
            int i = this.m_nextSegmentIndex;
            if (i == this.m_segmentCount) {
                throw new IndexOutOfBoundsException();
            }
            this.m_nextSegmentIndex = i + 1;
        }
        return this.m_currentSegment;
    }

    public Segment previousSegment() {
        if (this.m_bCirculator) {
            int i = this.m_segmentCount;
            this.m_nextSegmentIndex = ((this.m_nextSegmentIndex + i) - 1) % i;
        } else {
            int i2 = this.m_nextSegmentIndex;
            if (i2 == 0) {
                throw new IndexOutOfBoundsException();
            }
            this.m_nextSegmentIndex = i2 - 1;
        }
        if (this.m_nextSegmentIndex != this.m_currentSegmentIndex) {
            _updateSegment();
        }
        return this.m_currentSegment;
    }

    public void resetToFirstSegment() {
        this.m_currentSegmentIndex = -1;
        this.m_nextSegmentIndex = 0;
    }

    public void resetToLastSegment() {
        this.m_nextSegmentIndex = this.m_segmentCount;
        this.m_currentSegmentIndex = -1;
    }

    public void resetToVertex(int i) {
        int pathStart;
        int i2 = this.m_currentPathIndex;
        if (i2 >= 0 && i2 < this.m_parent.getPathCount() && i >= (pathStart = this.m_parent.getPathStart(this.m_currentPathIndex)) && i < this.m_parent.getPathEnd(this.m_currentPathIndex)) {
            this.m_currentSegmentIndex = -1;
            this.m_nextSegmentIndex = i - pathStart;
            return;
        }
        int pathIndexFromPointIndex = this.m_parent.getPathIndexFromPointIndex(i);
        this.m_nextPathIndex = pathIndexFromPointIndex + 1;
        this.m_currentPathIndex = pathIndexFromPointIndex;
        this.m_currentSegmentIndex = -1;
        this.m_nextSegmentIndex = i - this.m_parent.getPathStart(pathIndexFromPointIndex);
        this.m_segmentCount = _getSegmentCount(pathIndexFromPointIndex);
    }

    public boolean nextPath() {
        int i = this.m_nextPathIndex;
        this.m_currentPathIndex = i;
        if (i >= this.m_parent.getPathCount()) {
            return false;
        }
        this.m_currentSegmentIndex = -1;
        this.m_nextSegmentIndex = 0;
        this.m_segmentCount = _getSegmentCount(this.m_currentPathIndex);
        this.m_nextPathIndex++;
        return true;
    }

    public boolean previousPath() {
        int i = this.m_nextPathIndex;
        if (i == 0) {
            return false;
        }
        int i2 = i - 1;
        this.m_nextPathIndex = i2;
        this.m_currentSegmentIndex = -1;
        this.m_nextSegmentIndex = 0;
        this.m_segmentCount = _getSegmentCount(i2);
        this.m_currentPathIndex = this.m_nextPathIndex;
        resetToLastSegment();
        return true;
    }

    public void resetToFirstPath() {
        this.m_currentSegmentIndex = -1;
        this.m_nextSegmentIndex = -1;
        this.m_segmentCount = -1;
        this.m_nextPathIndex = 0;
        this.m_currentPathIndex = -1;
    }

    public void resetToLastPath() {
        this.m_nextPathIndex = this.m_parent.getPathCount();
        this.m_currentPathIndex = -1;
        this.m_currentSegmentIndex = -1;
        this.m_nextSegmentIndex = -1;
        this.m_segmentCount = -1;
    }

    public void resetToPath(int i) {
        if (i < 0) {
            throw new IndexOutOfBoundsException();
        }
        this.m_nextPathIndex = i;
        this.m_currentPathIndex = -1;
        this.m_currentSegmentIndex = -1;
        this.m_nextSegmentIndex = -1;
        this.m_segmentCount = -1;
    }

    public int _getSegmentCount(int i) {
        if (this.m_parent.b()) {
            return 0;
        }
        return this.m_parent.getPathSize(i) - (!this.m_parent.isClosedPath(i));
    }

    public boolean isClosingSegment() {
        return this.m_currentSegmentIndex == this.m_segmentCount - 1 && this.m_parent.isClosedPath(this.m_currentPathIndex);
    }

    public void setCirculator(boolean z) {
        this.m_bCirculator = z;
    }

    public int getPathIndex() {
        return this.m_currentPathIndex;
    }

    public int getStartPointIndex() {
        return _getPathBegin() + this.m_currentSegmentIndex;
    }

    public int _getPathBegin() {
        return this.m_parent.getPathStart(this.m_currentPathIndex);
    }

    public int getEndPointIndex() {
        if (isClosingSegment()) {
            return this.m_parent.getPathStart(this.m_currentPathIndex);
        }
        return getStartPointIndex() + 1;
    }

    public boolean isFirstSegmentInPath() {
        return this.m_currentSegmentIndex == 0;
    }

    public boolean isLastSegmentInPath() {
        return this.m_currentSegmentIndex == this.m_segmentCount - 1;
    }

    public boolean hasNextSegment() {
        return this.m_nextSegmentIndex < this.m_segmentCount;
    }

    public boolean hasPreviousSegment() {
        return this.m_nextSegmentIndex > 0;
    }

    public SegmentIteratorImpl copy() {
        SegmentIteratorImpl segmentIteratorImpl = new SegmentIteratorImpl(this.m_parent);
        segmentIteratorImpl.m_currentSegmentIndex = this.m_currentSegmentIndex;
        segmentIteratorImpl.m_nextSegmentIndex = this.m_nextSegmentIndex;
        segmentIteratorImpl.m_segmentCount = this.m_segmentCount;
        segmentIteratorImpl.m_currentPathIndex = this.m_currentPathIndex;
        segmentIteratorImpl.m_nextPathIndex = this.m_nextPathIndex;
        segmentIteratorImpl.m_parent = this.m_parent;
        segmentIteratorImpl.m_bCirculator = this.m_bCirculator;
        return segmentIteratorImpl;
    }

    public void _updateSegment() {
        int i = this.m_nextSegmentIndex;
        if (i < 0 || i >= this.m_segmentCount) {
            throw new IndexOutOfBoundsException();
        }
        this.m_currentSegmentIndex = i;
        int startPointIndex = getStartPointIndex();
        this.m_parent._verifyAllStreams();
        AttributeStreamOfInt8 segmentFlagsStreamRef = this.m_parent.getSegmentFlagsStreamRef();
        int read = segmentFlagsStreamRef != null ? segmentFlagsStreamRef.read(startPointIndex) & 7 : 1;
        VertexDescription description = this.m_parent.getDescription();
        if (read != 1) {
            if (read == 2) {
                throw new GeometryException("internal error");
            }
            if (read == 4) {
                throw new GeometryException("internal error");
            }
            throw new GeometryException("internal error");
        }
        if (this.m_line == null) {
            this.m_line = new Line();
        }
        Line line = this.m_line;
        this.m_currentSegment = line;
        line.a(description);
        int endPointIndex = getEndPointIndex();
        this.m_parent.getXY(startPointIndex, this.m_dummyPoint);
        this.m_currentSegment.c(this.m_dummyPoint);
        this.m_parent.getXY(endPointIndex, this.m_dummyPoint);
        this.m_currentSegment.e(this.m_dummyPoint);
        int attributeCount = description.getAttributeCount();
        for (int i2 = 1; i2 < attributeCount; i2++) {
            int semantics = description.getSemantics(i2);
            int componentCount = VertexDescription.getComponentCount(semantics);
            for (int i3 = 0; i3 < componentCount; i3++) {
                this.m_currentSegment.a(semantics, i3, this.m_parent.getAttributeAsDbl(semantics, startPointIndex, i3));
                this.m_currentSegment.b(semantics, i3, this.m_parent.getAttributeAsDbl(semantics, endPointIndex, i3));
            }
        }
    }

    boolean a() {
        return this.m_currentPathIndex == this.m_parent.getPathCount() - 1;
    }
}
